import unittest

import xlwings

from autoTask.core import taskMapping
from autoTask.taobao.sycm.gjc.gjc_hyc_robot.parseExcelToTitle import ParseExcelToTitle, TargetProduct
from common.utils import FileUtil, web_page_util
from common.utils.web_page_util import MockMove, MockTap


class MyTestCase(unittest.TestCase):

    def setUp(self):
        # self.sheet = xlwings.Book(
        #     FileUtil.get_project_root() + r"/DownloadData/sycm_table/gjc_hyc_data_clean/result/任务报表.xlsx") \
        #     .sheets["市场排行版词+延申词"]
        self.p = web_page_util.create_page()
        self.param = {
            "taskId": "4",
            "taskName": "生意参谋-关键词-行业词",
            "param": {
                "account": "赫巴兹直销企业店:数据",
                "password": "aa123456",
                "searchContent": "蒸锅",
                "isOperationTitle": True,
                "isAutoAppendKeyWord": True,
                "relatedDay": 7,
                "hotTermDay": 30,
                "dataWord": "搜索词",
                "tableTopic": [],
                "dealValue": 1000,
                "payNum": 30,
                "price": 128,
                "blockWords": [
                    "苏泊尔",
                    "章丘",
                    "官方",
                    "空气炸锅",
                    "炊大皇",
                    "康巴赫",
                    "铸铁锅",
                    "树可",
                    "卡罗特",
                    "三禾",
                    "wmf",
                    "九阳",
                    "双立",
                    "帝",
                    "荣",
                    "爱",
                    "乐",
                    "角",
                    "陶瓷",
                    "铁",
                    "迈巴勒",
                    "乌兹别克斯坦",
                    "一层",
                    "二层",
                    "三层",
                    "四层",
                    "五层",
                    "六层",
                    "双层",
                    "商用",
                    "洛德",
                    "陶土",
                    "欧洛德",
                    "小蒸锅"
                ],
                "dealNum": 10000,
                "hotIndex": 4,
                "searchNum": 10000,
                "payRate": 10,
                "numOfPay": 500,
                "matchesType": "精准匹配",
                "targetProductMap": [
                    {
                        "productId": "672228788728",
                        "titlePrefix": "格洛恩",
                        "titleSuffix": "蒸锅",
                        "titleMaxLength": 60,
                        "ignoreCuts": [
                            "陶",
                            "角",
                            "电池"
                        ]
                    },
                    {
                        "productId": "671901195976",
                        "titlePrefix": "格洛恩",
                        "titleSuffix": "蒸锅",
                        "titleMaxLength": 60,
                        "ignoreCuts": [
                            "陶",
                            "角",
                            "电池"
                        ]
                    }
                ],
                "rmEnglish": True,
                "percent": 60,
                "priceCap": 1
            }
        }

    def test_parse_action(self):
        target_product = TargetProduct("679312785018", title_prefix="德国316不锈钢",
                                       ignore_cuts=['陶', '角', '电池', '蒸', '可用'])
        ParseExcelToTitle(sheet=self.sheet,
                          target_product_list=[target_product],
                          ignore_keys=['铁', '官', '康', '大', '铁', '禾', '乐', '记', '达', '巴', '旗', '之',
                                       '土', '双'], page=self.p, is_test_execute=True)()

    def test_demo(self):
        # taskMapping.task_gjc_hyc_run(self.param)
        # MockTap("tag=span@@text()=商品", before_delay=(2, 3), after_delay=(2, 3), reduce_scope=(1, 10),
        #         msg="点击商品标签页失败")(self.p)
        print(self.p("tag=span@@text()=商品",timeout=0))
        print(self.p("tag=a@@text()=我的宝贝",timeout=0))


if __name__ == '__main__':
    unittest.main()
